package com.jhhc.FloodForecast.FloodForecast02.util;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HttpUtil {




    /**
     * 获取预报基础信息列表
     * @param url
     */
    public String getForecastBaseInfo(String url,String projectId){
        url = url + "/JHHC02/FloodForecast/GetForecastBaseInfo";
        CloseableHttpClient httpClient = HttpClients.createDefault();  //http请求
        // 设置URI
        try {
            URIBuilder builder = new URIBuilder(url);
            builder.setParameter("projectId", projectId);
            URI uri = builder.build();
            HttpGet httpGet = new HttpGet(uri);
            //超时时间 单位：毫秒
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(60000)
                    .setConnectionRequestTimeout(60000).setSocketTimeout(60000).build();
            httpGet.setConfig(requestConfig);
            httpGet.setHeader("Content-Type", "application/json; charset=utf-8");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            HttpEntity entity = response.getEntity();
            return EntityUtils.toString(entity, "UTF-8");
        } catch (URISyntaxException | IOException e) {
            e.printStackTrace();
            System.out.println("接口请求异常");
            return null;
        }
    }
}
